assertThat( 'pExpected' : 'pActual' : pMatcher [: 'message');
Asserts that the data addressed by 'pExpected' and 'pActual' satisfies the condition specified by
procedure 'pMatcher'. The assertion fails if the matcher returns *off
.
This asssertion can be used for comparing very large string values or any other types of complex data, such as XML or Json.
Return value:void
Example 1 (string):
expected = 'Donald Duck';
actual = 'Dagobert Duck';
assertThat( %addr(expected) :
%addr(actual) :
%paddr(matcherProcedure));
In the example above, the matcher procedure should return *off
, because
obviously 'Donald Duck' does not match 'Dagobert Duck'.
dcl-ds data_t qualified template;
type char(10);
seqNbr int(10);
itemNbr char(10);
end-ds;
dcl-ds expected likeds(data_t) inz;
dcl-ds actual likeds(data_t) inz;
dcl-pr matcher ind;
expected pointer const;
actual pointer const;
message like(msgText_t) options(*nopass);
end-pr;
expected.type = '*ITEM';
expected.seqNbr = 1;
actual.type = '*ITEM';
actual.seqNbr = 2;
assertThat( %addr(expected) :
%addr(actual) :
%paddr(matcher));
// -------------------------------------------------------
// Procedure for comparing 'expected'with 'actual'.
// -------------------------------------------------------
dcl-proc matcher export;
dcl-pi *n ind;
expected pointer const;
actual pointer const;
message like(msgText_t) options(*nopass);
end-pi;
dcl-ds expectedData likeds(data_t) based(expected);
dcl-ds actualData likeds(data_t) based(actual);
if (expectedData.type = actualData.type and
expectedData.seqNbr = actualData.seqNbr and
expectedData.itemNbr = actualData.itemNbr);
return *on;
else;
return *off;
endif;
end-proc;
In the example above, the matcher must compare the data structures and return *on
or *off
depending on the result. Most likely it returns *off
, because
neither the 'type' nor the 'seqNbr' do match.